//
//  HotViewController.m
//  xxShare
//
//  Created by 柳麟喆 on 2018/4/1.
//  Copyright © 2018年 lzLiu. All rights reserved.
//

#import "HotViewController.h"
#import "HotTableViewCell.h"
#import "OneFeedViewController.h"
#import "FeedModel.h"

@interface HotViewController ()<UITableViewDelegate, UITableViewDataSource>

@property(nonatomic, strong)UITableView *tableview;

@property (nonatomic, copy)NSMutableArray *testData;

@end

@implementation HotViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.llz_width, self.view.llz_height) style:UITableViewStyleGrouped];
    _tableview.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
    _tableview.sectionFooterHeight = 1;
    _tableview.dataSource = self;
    _tableview.delegate = self;
    _tableview.backgroundColor = BACKGROUND_COLOR;
    [self.view addSubview:_tableview];
    [_tableview registerNib:[UINib nibWithNibName:@"HotTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"HotTableViewCell"];
    
    _testData = [[NSMutableArray alloc]init];
    _testData = [self addTestData];
    
}

#pragma mark - *******tableviewDelegate dataSource*******

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    static NSString *identify = @"HotTableViewCell";
    HotTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identify forIndexPath:indexPath];
    [cell setModel:_testData[indexPath.row]];
    
    return cell;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _testData.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView cellForRowAtIndexPath:indexPath].selected = NO;
    OneFeedViewController *one = [[OneFeedViewController alloc]init];
    one.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:one animated:YES];
}

#pragma mark - *******布局*******
- (void)viewDidLayoutSubviews{
    _tableview.frame = self.view.bounds;
}

#pragma mark - *******添加测试数据*******
- (NSMutableArray *)addTestData{
    NSMutableArray *Data = [[NSMutableArray alloc]init];
    NSArray *nameArr = @[@"胖虎",@"叮当猫",@"哪吒",@"球球",@"可达鸭"];
    NSArray *moneyArr = @[@"232",@"432",@"99",@"178",@"392"];
    NSArray *imageArr = @[@"风景13",@"美食1",@"风景1",@"军事1",@"萌宠1"];
    for (int i = 1; i < 6; i++) {
        NSDictionary* dic = @{
                              @"name":nameArr[i-1],
                              @"moneyNum":moneyArr[i-1],
                              @"photos":@[imageArr[i-1]],
                              };
        FeedModel *model = [[FeedModel alloc]initWithFeedModel:dic];
        [Data addObject:model];
    }
    return Data;
}
@end
